package uk.co.BexhillWeb.MediaManager.Managers;

import javax.swing.event.EventListenerList;

import uk.co.BexhillWeb.MediaManager.EventUtilities.CustomEvent;
import uk.co.BexhillWeb.MediaManager.EventUtilities.CustomListener;

public final class EventManager {

	private static EventListenerList eventList = new EventListenerList();
	
	public static void addMyEventListener(CustomListener listener) {
		eventList.add(CustomListener.class, listener);
    }
	
	public static void removeMyEventListener(CustomListener listener) {
		eventList.remove(CustomListener.class, listener);
    }
	
	public static void fireMyEvent(CustomEvent evt) {
        Object[] listeners = eventList.getListenerList();
        // Each listener occupies two elements - the first is the listener class
        // and the second is the listener instance
        for (int i=0; i<listeners.length; i+=2) {
            if (listeners[i]==CustomListener.class) {
                ((CustomListener)listeners[i+1]).EventOccurred(evt);
            }
        }
    }
}
